import debug = require('debug');
import {LogType} from "./defines";

export default class Logger {
    private _loggers: any[] = [];

    constructor(appName: string){
        this._loggers[ LogType.INFO  ] = debug( `${appName}:INF` );
        this._loggers[ LogType.DEBUG ] = debug( `${appName}:DBG` );
        this._loggers[ LogType.WARN  ] = debug( `${appName}:WRN` );
        this._loggers[ LogType.ERROR ] = debug( `${appName}:ERR` );
    }

    log(type: LogType, format: string, content?: any){
        let log = this._loggers[type];
        if(log.enabled) {
            log(format, content || '');
        }
    }

    I(format: string, content?: any){
        this.log(LogType.INFO, format, content);
    }

    D(format: string, content?: any){
        this.log(LogType.DEBUG, format, content);
    }

    W(format: string, content?: any){
        this.log(LogType.WARN, format, content);
    }

    E(format: string, content?: any){
        this.log(LogType.ERROR, format, content);
    }
};
